package com.zl.bootsecurityjwt.mapper;

import com.zl.bootsecurityjwt.model.JwtParam;
import com.zl.bootsecurityjwt.model.Permissions;
import com.zl.bootsecurityjwt.model.Role;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.Set;

@Mapper
public interface UserMapper {
    @Select("select username,password from user where username= #{userName}")
    public JwtParam getUserInfo(String userName);

    @Select("select c.* from user a \n" +
            "left join  user_role b on a.id=b.user_id\n" +
            "left join role c on b.role_id=c.id" +
            " where a.username=#{userName}")
    public Set<Role> getRole(String userName);

    @Select("select * from permissions a\n" +
            "left join role_permissions b on a.id=b.permissions_id\n" +
            " where b.role_id in (1,2)")
    Set<Permissions> getPermissions(Set<Role> role);
}
